package com.liu.controller;

import com.alipay.api.AlipayApiException;
import com.liu.bean.AlipayBean;
import com.liu.service.PayService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController()
@RequestMapping("order")
public class OrderController {
    @Resource
    private PayService payService;//调用支付服务
    /*阿里支付*/
    @RequestMapping(value = "pay")
    public String alipay() throws AlipayApiException {
        Date now = new Date(); // 创建一个Date对象，获取当前时间
        // 指定格式化格式
        SimpleDateFormat f = new SimpleDateFormat("yyyyMMddHHmmss");
        return  payService.aliPay(new AlipayBean()
                .setBody("商品描述")
                .setOut_trade_no(f.format(now))
                .setTotal_amount(new StringBuffer().append(888))//价格
                .setSubject("商品类型"));
    }
}
